package com.example.test.mapper;

import com.example.test.entity.Role;
import com.example.test.entity.UserRole;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

@Mapper
public interface UserRoleMapper {

    @Select("select * from user_role")
    List<UserRole> findAll();

    @Select({
            "<script>",
            "select * from user_role where uid in ",
            "<foreach collection='userIds' item='uid' index='index' open='(' separator=',' close=')'>",
            "#{uid}",
            "</foreach>",
            "</script>"
    })
    List<UserRole> findAllByUid(@Param("userIds") List<Integer> userIds);

    //新增数据
    @Insert("insert into user_role(uid,role_id) values (#{uid},#{roleId})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int save(UserRole userRole);


    List<Role> getRoleByUid(Integer uid);

}